package think.thread.c07.countdownlatch;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class CountDownLatchDemo {
	public static void main(String[] args) {
		
		ExecutorService exec = Executors.newCachedThreadPool();
		
		int size=100;
		
		CountDownLatch latch=new CountDownLatch(size);
		for(int i=0;i<10;i++){
			exec.execute(new WaitTask(latch));
		}
		
		for(int i=0;i<size;++i){
			exec.execute(new TaskPortion(latch));//size-1个线程
		}
		latch.countDown();
		System.out.println("Launched all tasks");
		
		exec.shutdown();
		
	}
}
